package zcy.sort;

/**
 * https://zhuanlan.zhihu.com/p/395036758
 */
public class BubbleSort {


    public static void bubbleSort(int[] arr){
        for (int i=0; i<arr.length; i++) {
            for (int k=i+1 ; k<arr.length; k++){
                if (arr[i]>arr[k]){
                    swap(arr,i,k);
                }
            }
        }
    }

    private static void swap(int[] arr, int i, int k) {
        int tmp;
        tmp=arr[i];
        arr[i] = arr[k];
        arr[k] = tmp;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1,3,2};
        bubbleSort(arr);
        for (int i : arr) {
            System.out.println(i);
        }
    }

}
